package buttons.view;

import java.awt.Color;

import processing.core.PApplet;
import processing.core.PVector;

/*
 * This class stores data relevant to displaying the axis correctly on the grid view
 * it also supports changing the data and notifying the grid view 
 */
public class V_VerticalDoubleSlider extends V_DoubleSlider
{  
  public V_VerticalDoubleSlider(String n, float xWidth, float yHeight){
    super(n, xWidth, yHeight);
    this.setBGColor(new Color(255, 255, 255));
    rect1 = 0.0f;
    rect2 = ySize;
  }
  
  @Override
  public void display(PApplet p)
  {
    if(visible)
    { 
      int tmpColor = p.color(p.red(bgColor)+offset, p.green(bgColor)+offset, p.blue(bgColor)+offset, transp); 
      p.stroke(0,0,0,transp);
      p.fill(tmpColor);    
      p.rect(xLoc, yLoc, xSize, ySize);
      
      p.noStroke();
      p.fill(200-r1_ColorOffset, 200-r1_ColorOffset, 200-r1_ColorOffset, transp-100);
      p.rect(xLoc, yLoc+rect1, xSize, rectWidth);
      p.fill(200-r2_ColorOffset, 200-r2_ColorOffset, 200-r2_ColorOffset, transp-100);
      p.rect(xLoc, yLoc+rect2-rectWidth, xSize, rectWidth);
      
      p.fill(240-r3_ColorOffset, 240-r3_ColorOffset, 240-r3_ColorOffset, transp);
      p.rect(xLoc+1, yLoc+rect1+rectWidth, xSize-1, rect2-rectWidth-(rect1+rectWidth));
    }
  }
  
  // determines what part of the slider the mouse is over:
  @Override
  public int containsWhat(float xVal, float yVal)
  {
    // check if mouse is over the first rectangle:
    if (yVal < yLoc + rect1 + rectWidth && yVal > yLoc + rect1
      && xVal < xLoc + xSize && xVal > xLoc)
    {
      return 0;
    }
    // check if mouse is over the second rectangle:
    else if (yVal < yLoc + rect2 && yVal > yLoc+rect2-rectWidth
      && xVal < xLoc + xSize && xVal > xLoc)
    {
      return 1;
    }
    // check if mouse is over the big rectangle:
    else if (yVal < yLoc + rect2-rectWidth && yVal > yLoc+rect1+rectWidth
      && xVal < xLoc + xSize && xVal > xLoc)
    {
      return 2;
    }
    
    else
    {
      return -1;
    }
  }
  @Override
  public void moveRect1(float m)
  {
    rect1 = Math.max(0, Math.min(rect2-(rectWidth*2), m));
  }
  @Override
  public void moveRect2(float m)
  {
    rect2 = Math.max(rect1+(rectWidth*2), Math.min(ySize, m));
  }
  @Override
  public float getXPercent()
  {
    return rect1/ySize;
  }
  @Override
  public float getYPercent()
  {
    return rect2/ySize;
  }
  @Override
  public PVector getAllPercents()
  {
    return new PVector(rect1/ySize, rect2/ySize);
  }
}